﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SY.WebSite.BLL;

namespace SY.WebSite.Web.Jifen
{
    public partial class LotteryOpen : BasePage
    {
        public Entity.Lottery CurrentLottery;
        public IList<Hashtable> Participants;
        public IList<Hashtable> Lucky; 

        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Tools.Web.Request.GetQueryInt("id", 0);
            if (id <= 0)
                return;

            CurrentLottery = BizLottery.GetByKey(id);
            if (CurrentLottery == null)
            {
                RedirectTo404Page("当前抽奖信息不存在");
                return;
            }
            //if (CurrentLottery.UserId != CurrentUser.UserId)
            //{
            //    RedirectToAuthorityPage("您不是当前【" + CurrentLottery.Title + "】的创建者 " + CurrentLottery.UserName);
            //    return;
            //}
            //if (CurrentLottery.Status == 1)
            //{
            //    RedirectTo404Page("【"+CurrentLottery.Title+"】已经开奖过");
            //    return;
            //}
            //if (CurrentLottery.OpenTime >DateTime.Now)
            //{
            //    RedirectToAuthorityPage("【" + CurrentLottery.Title + "】尚未结束，等结束后再来吧");
            //    return;
            //}
            Participants = BizLottery.GetParticipants(CurrentLottery.Participants);
            if (!string.IsNullOrEmpty(CurrentLottery.Lucky))
            {
                Lucky = BizLottery.GetParticipants(CurrentLottery.Lucky);
            }
            else
            {
                List<Hashtable> black = new List<Hashtable>();
                if (!string.IsNullOrEmpty(CurrentLottery.Forbidden))
                    black = BizLottery.GetParticipants(CurrentLottery.Forbidden);

                Lucky = new List<Hashtable>();
                foreach (var hashtable in Participants)
                {
                    if (black.Count(l => l["JobNumber"].ToString() == hashtable["JobNumber"].ToString()) == 0)
                        Lucky.Add(hashtable);
                }
            }
        }
    }
}